package cn.edu.cjw.APMFP.Util;

import cn.edu.cjw.APMFP.ui.CenterPanel;
import cn.edu.cjw.APMFP.ui.LoginFrame;
import cn.edu.cjw.APMFP.ui.MainFrame;
import cn.edu.cjw.APMFP.user.pojo.User;

import javax.swing.*;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @package cn.edu.cjw.APMFP.Util
 * @className CacheUtil
 * @note TODO
 * @author wind
 * @date 2022/3/12 14:12
 */
public class CacheUtil {

    private final static Map<String, User> MAP = new ConcurrentHashMap<>();

    private final static String KEY = "token";

    public static void login(User user){
        MAP.put(KEY, user);
    }

    public static User getUser(){
        return getUser(null);
    }

    public static User getUser(CenterPanel centerPanel){
        User user = MAP.get(KEY);
        if(user == null){
            JOptionPane.showMessageDialog(null, "用户不存在, 请重新登陆");
            System.exit(-1);
        }
        return user;
    }
}
